use sea_orm_migration::{prelude::*, schema::*};

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .create_table(
                Table::create()
                    .table(TaskStep::Table)
                    .if_not_exists()
                    .col(pk_auto(TaskStep::Id))
                    .col(integer(TaskStep::GitlabInfoId))
                    .col(tiny_integer(TaskStep::TaskType))
                    .col(string_null(TaskStep::ParamJson))
                    .col(date_time_null(TaskStep::StartTime))
                    .col(date_time_null(TaskStep::EndTime))
                    .col(tiny_integer(TaskStep::StepState))
                    .col(date_time_null(TaskStep::RuntimeData))
                    .to_owned(),
            )
            .await
    }

    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .drop_table(Table::drop().table(TaskStep::Table).to_owned())
            .await
    }
}

#[derive(DeriveIden)]
enum TaskStep {
    Table,
    Id,
    GitlabInfoId,
    TaskType,
    ParamJson,
    StartTime,
    EndTime,
    StepState,
    RuntimeData,
}
